package com.fuchuang.seckillsystem.timer;

import com.fuchuang.seckillsystem.service.ISeckillService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

@Component
public class ActivityTimer {
    
    @Autowired
    private ISeckillService seckillService;
    
    /**
     * 将商品库存预加载到redis中   每10分钟执行一次
     */
    @Scheduled(cron = "0 0/10 * * * ? ")
    public void loadGoodsPushRedis() {
        //不加载正在秒杀的秒杀活动
        seckillService.insertGoodsToRedis(false);
    }
    
    /**
     * 单机部署时，采用了本地缓存，为防止内存溢出，每天根据是否有秒杀活动清空isEmpty中的数据
     */
    @Scheduled(cron = "0 0 1 * * ? ")
    public void deleteMap() {
        seckillService.resetIsEmpty();
    }
    
}
